$(document).ready(function(){
    //下载App隐藏的二维码部分
    $(".download").hover(function(){
        $(".downloadHide").toggle();
    });
    $(".downloadHide").hover(function(){
        $(".downloadHide").toggle();
    });
    $(".heartO").click(function(){
        $(".heartO").hide();
        $(".heart1").show();
    });
    $(".heart1").click(function(){
        $(".heart1").hide();
        $(".heartO").show();
    });

    //登录之后个人信息的下拉菜单部分
    $(".myselfPic").hover(function(){
        $(".myselfDownList").toggle();
    });
    $(".myselfDownList").hover(function(){
        $(".myselfDownList").toggle();
    });
    //退出用户
    $(".loginOut").click(function () {
        $.ajax({
            type:"post",
            url: "/user/loginOut",
            data: {},
            success: function (data) {
                alert(data.msg);
                window.location.href="/user/sign";
            },
            error: function () {

            }
        });
    });
    //点赞的切换
    $(".agree").click(function(){
        var blogId = $(".bId").val();
        if ($(".like").val()=='true') {
            $.ajax({
                type:"post",
                url:"/praise/unlikeBlog",
                data: {
                    bid:blogId
                },
                success: function (data) {
                    if (data.success==true) {
                        $(".like").val("false");
                        $('.zan').attr('src','/static/images/zan2.png')
                    }
                },
                error: function () {

                }
            });
        }else{
            $.ajax({
                type:"post",
                url:"/praise/likeBlog",
                data: {
                    blogId:blogId
                },
                success: function (data) {
                    if (data.success==true) {
                        $(".like").val("true");
                        $('.zan').attr('src','/static/images/zan.png')
                    }
                },
                error: function () {

                }
            });
        }
    });

    //加关注部分的切换
    $(".leftUserImgLove0").click(function () {
         var authorId =$(".authorId").val();
        if ($(".leftUserLove").val()=='true') {
            $.ajax({
                type: "post",
                url: "/focus/cancelFocus",
                data: {
                    authorId: authorId
                },
                success: function (data) {
                    if (data.success == true) {
                        $('.leftUserImgLove1').removeClass('leftUserImgLove1').addClass('leftUserImgLove');
                        $(".leftUserLove").val("false");
                        if($('.love').text()=='加关注'){
                            $('.love').text('取消关注')
                        }else{
                            $('.love').text('加关注')
                        }
                    }
                },
                error: function () {

                }
            });
        }else{
            $.ajax({
                type:"post",
                url:"/focus/addFocus",
                data: {
                    authorId:authorId
                },
                success: function (data) {
                    if (data.success==true) {
                        $('.leftUserImgLove').removeClass('leftUserImgLove').addClass('leftUserImgLove1');
                        $(".leftUserLove").val("true");
                        if($('.love').text()=='加关注'){
                            $('.love').text('取消关注')
                        }else{
                            $('.love').text('加关注')
                        }
                    }
                },
                error: function () {

                }
            });
        }

    });
    // $(".leftUserImgLove").click(function () {
    //     $(".leftUserImgLove1").show();
    //     $(".leftUserImgLove").hide();
    // });
    // $(".leftUserImgLove1").click(function () {
    //
    //     $(".leftUserImgLove").show();
    //     $(".leftUserImgLove1").hide();
    // });
    //提交搜索框form表单的非空校验
    $(".navBtn").click(function(){
        var input = $("input[name='inputName']").val();
        if (input == "" || input == null || input == undefined) {
            alert("搜索不能为空");
            return false;/*阻止表单提交*/
        } else {
            alert("提交");
            $(".navBtn").submit();
        }
    });
    //评论框
    // $(".textarea").blur(function(){
    //     $(".textarea").css("width","100px");
    //     $(".textarea").css("transition","none");
    // });
    // 提交评论
    $(".showButton").click(function () {
        var bId = $(".bId").val();
        var cAddress = $(".textarea").val();
        var speakText = $(".speakText").text();
        var speakName = $(".uname").val();
        var myDate = new Date;
        var year = myDate.getFullYear(); //获取当前年
        var mon = myDate.getMonth(); //获取当前月
        var date = myDate.getDate(); //获取当前日
        var h = myDate.getHours();       //获取当前小时数(0-23)
        var m = myDate.getMinutes();     //获取当前分钟数(0-59)
        var s = myDate.getSeconds();
        var picture = $(".picture").val();

        // speakText.html($(".textarea").val());
        $.ajax({
            type:"post",
            url:"/comment/addComment",
            data: {
                bId:bId,
                cAddress:cAddress
            },
            success: function () {
                var Str = '<div class="speakOther"><img src="'+picture+'"/><span class="speakName">'+speakName+' : '+' </span>  '+'<div class="speakText" >'+cAddress+'</div>' +'<span class="speaktime" >'+year+'-'+mon+'-'+date+' '+h+':'+m+':'+s+'</span>'+'<div class="speakReadreply"><span></span>'+'<span class="speakreply"></span> </div>';
                $(".allSpeakOther").prepend(Str);
            },

            error: function () {

            }
        });
    });

    // 查看回复
    $(".speakReadreply").click(function () {
        $(this).next().slideToggle();
        $(".price").show();
        $(".answer").show();
        $(function () {
            setTimeout(function () {
                $(".price").hide();
            }, 2000);
        })
        console.log($(this).next());
    })
    // 回复
//     $(".speakreply").click(function () {
//         $(".textarea").attr('placeholder','回复该条评论');
//         $(this).animate({ scrollTop: $('.textarea').offset().top }, 5000)
//     });
    /*提交*/
    $(".sumit").click(function () {
        var text=$('.answer').find('input').val();


    })
    // 收藏博客
    $(".collect").click(function(){
        var blogId = $(".bId").val();
        if ($(".collectInput").val()=='true') {
            $.ajax({
                type:"post",
                url:"/collection/deleteBlogCollection",
                data: {
                    blogId:blogId
                },
                success: function (data) {
                    if (data.success==true) {
                        $(".collectInput").val("false");
                        $('.collectImg').attr('src','/static/images/collect1.png')
                        // $('.zan').attr('src','/static/images/zan.png')
                    }
                },
                error: function () {

                }
            });
        }else{
            $.ajax({
                type:"post",
                url:"/collection/collectionBlog",
                data: {
                    blogId:blogId
                },
                success: function (data) {
                    if (data.success==true) {
                        $(".collectInput").val("true");
                        $('.collectImg').attr('src','/static/images/collect2.png')
                    }
                },
                error: function () {

                }
            });
        }
    });
});
